<cfcomponent name="person" displayname="person" hint="person funks">

	<cffunction name="init" returntype="any" access="public" output="false">
		<cfargument name="personRecord" required="true" />
		<cfset variables.personRecord = arguments.personRecord />
		<cfreturn this />
	</cffunction>
	
	<cfinclude template="funk.cfm">

	<cffunction name="setRequestFromQry" output="false" returntype="boolean">
	 <cfargument name="daQry" hint="query is needed" type="query" required="true">
	   <cfloop list="#daQry.columnlist#" index="dc">
	    <cfset "request.#dc#" = "#evaluate('daQry.'&dc)#">
	   </cfloop>
	   <cfreturn true>
	</cffunction>

	<cffunction name="personlist" displayname="personlist" hint="person list" access="package" output="true" returntype="any">
		<cfparam name="url.viewingGroupID" default="">
		<cflock scope="session" timeout="10" type="exclusive">
		  <cfif isDefined('url.groupID')><cfset session.viewingGroupID = url.groupID></cfif>
			<cfparam name="url.viewingAll" default="false">
		  <cfif isDefined('url.viewingAll')><cfset session.viewingAll = url.viewingAll></cfif>
		  
		</cflock>
		<cfquery name="getPeople" datasource="#request.dsource#">
		 SELECT people.personID, concat(people.lastname,', ',people.firstname) as Person, 
		   concat(ifNull(group_concat(DISTINCT groups.groupName)," None"),' ') as groups
		 FROM people LEFT JOIN peoplegroups ON people.personID = peoplegroups.personID
		 LEFT JOIN groups ON groups.groupID = peoplegroups.groupID
		 LEFT JOIN sectionInstructors ON sectionInstructors.personID = people.personID
		 LEFT JOIN section ON section.sectionID = sectionInstructors.sectionID
		 LEFT JOIN courseSubprograms ON courseSubprograms.courseID = section.courseID
		 LEFT JOIN programSubprograms ON programSubprograms.subprogramID = courseSubprograms.subprogramID
		 WHERE 1=1
		 <cfif url.viewingGroupID gt ''>
		  AND peoplegroups.groupID = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.viewingGroupID#">
		  <cfif url.viewingGroupID eq 5 AND NOT url.viewingAll>AND programSubprograms.programID IN (#request.user.programIDs#)</cfif>
		 </cfif>
		 GROUP BY personID, person
		 ORDER BY lastname
		</cfquery>
		<cfquery name="getSelGrps" dbtype="query">
		  SELECT distinct cast(groups as varchar) as groups from getPeople
		</cfquery>
		<h3>#getSelGrps.groups#</h3>
		<cfif url.viewingGroupID eq 5 AND url.viewingAll>
		 <b>Viewing All Programs</b> | <a href="#cgi.SCRIPT_NAME#?viewingAll=false">View My Program</a> | <a href="#cgi.SCRIPT_NAME#">View All People</a>
		<cfelseif url.viewingGroupID eq 5 AND NOT url.viewingAll>
		  <a href="#cgi.SCRIPT_NAME#?viewingAll=true&viewingGroupID=5">View All Programs</a> | <b>Viewing My Program</b> | <a href="#cgi.SCRIPT_NAME#">View All People</a> 
		<cfelse>
		 <b>Viewing All People</b> | <a href="/infobase/People/Instructors/index.cfm">View Instructors</a>
		</cfif> &nbsp; &nbsp; &nbsp; &nbsp; 
		<a href="#cgi.SCRIPT_NAME#?personID=0&e=1">Add Person</a>  
	  #daTable(daQry=getPeople, linkList='person:personID:#cgi.SCRIPT_NAME#', altRowColor='##eeeeee', border=1, width='80%')#
		<cfreturn />
	</cffunction>
	
	<cffunction name="instructorBios" output="true">
		<cfargument name="personID" required="true" type="numeric">
			<cfquery name="getBios" datasource="#request.dsource#">
				SELECT * FROM instructorBios WHERE personID = #personID#
				<cfif structKeyExists(url,"bioID")>AND bioID = #url.bioID#</cfif>
			</cfquery>
			<b>Instructor Bios</b> <a href="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#&bioID=0" style="font-weight:bold;">Add New</a>
			<cfloop query="getBios">| <a href="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#&bioID=#bioID#">#bioName#</a> </cfloop><br>
			<cfif isDefined('url.bioID')>
					<input type="hidden" name="bioID" value="#url.bioID#">
					&nbsp;&nbsp; Bio Name <input type="text" name="bioName" value="#getBios.bioName#">
					<br>&nbsp;&nbsp;&nbsp; <textarea name="bioText" cols="50">#getBios.bioText#</textarea><br>
					<input type="submit" name="saveBie" value="Save">
			</cfif>
			<br />
	</cffunction>

	<cffunction name="instructorAgreements" output="true">
	  <cfargument name="personID" required="yes" type="numeric">
	  <cfargument name="semesterID" default="">
		<h3>#request.user.semesterName# Instructor Agreements</h3>
			<cfquery name="getInstClasses" datasource="#request.dsource#">
				SELECT section.sectionID,
				 concat(course.courseNumber,' ',section.sectionname,' ',course.name) as coursename,
				 min(sectionSchedules.startdatetime) as Starts, max(sectionSchedules.endDateTime) as Ends
				 FROM people LEFT JOIN sectionSchedules ON people.personID = sectionSchedules.personID
				LEFT JOIN section ON section.sectionID = sectionSchedules.sectionID
				LEFT JOIN course ON course.courseID = section.courseID
				WHERE people.personID = #personID#
				<cfif semesterID gt ''>AND course.semesterID = #semesterID#</cfif>
				GROUP BY course.courseNumber,section.sectionname,course.name
				ORDER BY (course.courseNumber + 0)
			</cfquery>
			#daTable(daQry=getInstClasses,linkList='coursename:sectionID:../Courses/Sections/',
			         width="100%", altRowColor="##eeeeee")#
	</cffunction>

	<cffunction name="instructorCourses" output="true">
	  <cfargument name="personID" required="yes" type="numeric">
	  <cfargument name="semesterID" default="">
		<h3>#request.user.semesterName# Instructor Courses</h3>
			<cfquery name="getInstClasses" datasource="#request.dsource#">
				SELECT section.sectionID,
				 concat(course.courseNumber,' ',section.sectionname,' ',course.name) as coursename,
				 min(sectionSchedules.startdatetime) as Starts, max(sectionSchedules.endDateTime) as Ends
				 FROM people LEFT JOIN sectionSchedules ON people.personID = sectionSchedules.personID
				LEFT JOIN section ON section.sectionID = sectionSchedules.sectionID
				LEFT JOIN course ON course.courseID = section.courseID
				WHERE people.personID = #personID# 
				<cfif semesterID gt ''>AND course.semesterID = #semesterID#</cfif>
				GROUP BY course.courseNumber,section.sectionname,course.name
				ORDER BY (course.courseNumber + 0)
			</cfquery>
			#daTable(daQry=getInstClasses,linkList='coursename:sectionID:../Courses/Sections/',
			         width="100%", altRowColor="##eeeeee")#
			<br /><br /><h3>Sections</h3>
			<cfquery name="getInstClasses2" datasource="#request.dsource#">
				SELECT section.sectionID,
				 concat(course.courseNumber,' ',section.sectionname,' ',course.name) as coursename
				 FROM people LEFT JOIN sectionInstructors ON people.personID = sectionInstructors.personID
					LEFT JOIN section ON section.sectionID = sectionInstructors.sectionID
					LEFT JOIN sectionSchedules ON section.sectionID = sectionSchedules.sectionID
					LEFT JOIN course ON course.courseID = section.courseID
				WHERE people.personID = #personID#
				<cfif semesterID gt ''>AND course.semesterID = #semesterID#</cfif>
				GROUP BY course.courseNumber,section.sectionname,course.name
				ORDER BY (course.courseNumber + 0)
			</cfquery>
			#daTable(daQry=getInstClasses2,linkList='coursename:sectionID:../Courses/Sections/',
			         width="100%", altRowColor="##eeeeee")#
	</cffunction>

</cfcomponent>